package org.ResearchProject.service.serviceImpl;

import org.ResearchProject.service.WechatAutoService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 2024-12-15-13:41
 */
@Service
public class WechatAuthServiceImpl implements WechatAutoService {
    @Value("${Wechat.appid}")
    String APPID;
    @Value("${Wechat.secret}")
    String SECRET;
    String WECHAT_API_URL = "https://api.weixin.qq.com/sns/jscode2session";

    public String login(String code) {
        RestTemplate restTemplate = new RestTemplate();
        String url = WECHAT_API_URL + "?appid=" + APPID + "&secret=" + SECRET + "&js_code=" + code + "&grant_type=authorization_code";
        String response = restTemplate.getForObject(url, String.class);
        return response;
    }
}